<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\MovieBaseInfo;
use App\Jobs\CrawlerMovieJobs;

class GetAllMovies extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'daka:get-all-movies';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '采集数据库中的所有电影';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $ids = MovieBaseInfo::where('is_crawler', false)->where('crawler_count', '<', 3)->pluck('douban_id');
        if(count($ids) > 0) {
            foreach($ids as $id) {
                dispatch(new CrawlerMovieJobs($id));
            }
        }
    }
}
